<?php

namespace app\admin\validate;
use think\Validate;

class Library extends Validate
{

    //验证规则
    protected $rule = [
        'sysCodeName' 	=>  'uniqueCodeName',
        'subsystemName' =>  'uniqueSubsystemName',
    ];

    
    protected $scene = [
    		'add' => ['sysCodeName','subsystemName'],
    ];
    
    public function uniqueCodeName($value,$rule,$data){
    	$model = model('Library');
    	if($model->where('sysCodeName',$value)->count()>0 && $data['subsystemNo'] == 1){
    		return '项目名称已存在';
    	}
    	return true;
    }
    
    public function uniqueSubsystemName($value,$rule,$data){
    	$model = model('Library');
    	if($model->where('subsystemName',$value)->where('sysCode',$data['sysCode'])->count()>0){
    		return '项目内容已存在';
    	}
    	return true;
    }

}